home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Utilities / InstallerMaker™ / InstallerMaker__2.0.2_Installe / InstallerMaker™ 2.0.2 Installer / InstallerMaker Extensions / IEnd Extension / undoFol.IEnd.c next >
C/C++ Source or Header  |  1994-08-10  |  5KB  |  191 lines

  1. /*
  2.  
  3. The following source text is provided for the benefit of customers of
  4. Aladdin Systems, Inc., who wish to create custom Product Installers that
  5. incorporate functions similar to, but not exactly the same as, the undoFolder
  6. code resource that we supply on the StuffIt Installer Licensee disk.
  7.  
  8. If you are a licensee of our installation products, you may call Aladdin for technical
  9. support with this source code. Please contact Aladdin Developer Technical Support
  10. at (408) 761-6200. To license Aladdin installation technology, please contact
  11. Developer Product Licensing at the same telephone number. Or you can FAX us at
  12. (408) 761-6206.
  13.  
  14. */
  15.  
  16. #include <MacHeaders>
  17.  
  18.  
  19. //        IEnd.c        By Raymond Lau.
  20. //                    
  21. //        Copyright © 1992-94 Aladdin Systems, Inc. & Raymond Lau.
  22. //        All Rights Reserved.
  23. //        
  24. //        This source text produces an IEnd code-resource, which can
  25. //        be called by a Product Installer at the end of the installation
  26. //        process.  Specifications for IBeg, IMid, and IEnd code resources
  27. //        are given in the documentation for the StuffIt Installer™.
  28. //        
  29. //        This subroutine performs the following functions:
  30. //           
  31. //        • Move everything within the user-specified destination folder
  32. //          into the parent of that folder (i.e., one level up).
  33. //        • If an item cannot be moved to the parent directory because
  34. //          another item there already has the same name, then rename the
  35. //          item to be moved, before actually moving it.
  36. //        • Finally, delete the emptied user-specified folder.
  37. //        
  38. //        CHANGE HISTORY:
  39. //        
  40. //        VER    DATE        ENGR    DESCRIPTION
  41. //        1    93.04.14    rl        Initial version, some commentary added
  42. //                                by Jim Merritt (jam).
  43. //
  44. //        2    94.03.14    jam        Modified main to observe new packages
  45. //                                parameter for IEnd of ID = 128.
  46. //
  47. //        3    94.05.05    rmt        Rendered into ANSI C for Symantec C 6.0
  48. //                                by Robert Thorne (rmt).
  49. //
  50. //        4    94.08.10    rmt        Comments added on how to return correctly
  51. //                                by Robert Thorne (rmt).
  52. //
  53. //
  54. //
  55.  
  56.  
  57. // IMPORTANT NOTE ON THE "IEnd":  InstallerMaker relies on the IEnd to inform
  58. // the product installer whether installation was successful or not.  This gives
  59. // the developer the abillity to override the value passed to the IEnd in the 
  60. // "abort" parameter, and clean up after some "bad" installations, or declare
  61. // an installation as "bad" even if it has succeeded up to the time the IEnd is
  62. // called.  Be careful to test the "abort" parameter in any IEnd, and return the
  63. // appropriate code according to whether the installation is successful or failed
  64. // as appropriate for your installation.
  65.  
  66. // Valid return codes for an IEnd
  67. #define  kWasNotAborted 0
  68. #define  kWasAborted 1
  69.  
  70. // Type definitions
  71. typedef unsigned char uchar;
  72.  
  73. // Function Prototype
  74. uchar *pstrcat (uchar *s1, uchar *s2) ;
  75.  
  76.  
  77. /*
  78.     Concatenate the pascal string "s2" onto the end of the current
  79.     contents of the pascal string "s1".  Returns "s1".
  80. */
  81.  
  82.  
  83. uchar *pstrcat (uchar *s1, uchar *s2)
  84. {
  85.     short i;
  86.  
  87.     for (i = 1; i <= s2 [0]; ++i)
  88.         s1 [++s1 [0]] = s2 [i];
  89.  
  90.     return (s1);
  91. }
  92.  
  93.  
  94. pascal short main(short abort,short vol,long dir,uchar *name,
  95.                   unsigned short packages)
  96.  
  97. {    if(!abort) {
  98.         HParamBlockRec HRec;
  99.  
  100.         HRec.ioParam.ioNamePtr = (StringPtr)name;
  101.         HRec.ioParam.ioVRefNum = vol;
  102.         HRec.fileParam.ioDirID = dir;
  103.         HRec.fileParam.ioFDirIndex = 0;
  104.         
  105.         if(PBGetCatInfoSync((CInfoPBPtr)&HRec)) {
  106.             // really weird!  Nothing got unstuffed?
  107.             abort = TRUE;
  108.         } else {
  109.             long sourcedir = HRec.fileParam.ioDirID;
  110.             short i;
  111.             
  112.             if(!(HRec.fileParam.ioFlAttrib & 0x10))
  113.                 goto out;
  114.                 
  115.             i = 1;
  116.             for(;;) {
  117.                 short j;
  118.                 uchar str[10],newname[32],sourcename[32];
  119.                 CMovePBRec cmpb;
  120.  
  121.                 HRec.fileParam.ioFDirIndex = 1;
  122.                 HRec.fileParam.ioDirID = sourcedir;
  123.                 HRec.fileParam.ioVRefNum = vol;
  124.                 HRec.fileParam.ioNamePtr = sourcename;
  125.                 
  126.                 if(PBGetCatInfoSync((CInfoPBPtr)&HRec))
  127.                     break;
  128.                 
  129.                 j = 0;
  130.                     
  131.                 for(;;) {
  132.                     // see if it exists in the level above.
  133.                     BlockMove(sourcename,newname,32);
  134.                     if(j) {
  135.                         if(newname[0] > 28)
  136.                             newname[0] = 28;
  137.                         NumToString(j,str);
  138.                         pstrcat(newname,"\p.");
  139.                         pstrcat(newname,str);
  140.                     }
  141.                     HRec.fileParam.ioFDirIndex = 0;
  142.                     HRec.fileParam.ioDirID = dir;
  143.                     HRec.fileParam.ioVRefNum = vol;
  144.                     HRec.fileParam.ioNamePtr = newname;
  145.                     
  146.                     if(PBGetCatInfoSync((CInfoPBPtr)&HRec) == fnfErr) {
  147.                         if(!j)
  148.                             break;
  149.                         
  150.                         // hrumph -- check current level as well.
  151.                         HRec.fileParam.ioFDirIndex = 0;
  152.                         HRec.fileParam.ioDirID = sourcedir;
  153.                         HRec.fileParam.ioVRefNum = vol;
  154.                         HRec.fileParam.ioNamePtr = newname;
  155.                         
  156.                         if(PBGetCatInfoSync((CInfoPBPtr)&HRec) == fnfErr)
  157.                             break;
  158.                     }
  159.                     
  160.                     j++;
  161.                 }
  162.                 
  163.                 if(j) {
  164.                     HRec.fileParam.ioDirID = sourcedir;
  165.                     HRec.fileParam.ioVRefNum = vol;
  166.                     HRec.fileParam.ioNamePtr = (StringPtr)sourcename;
  167.                     HRec.ioParam.ioMisc = (Ptr)newname;
  168.                     PBHRenameSync(&HRec);
  169.                 }
  170.                 
  171.                 cmpb.ioNamePtr = (StringPtr)newname;
  172.                 cmpb.ioVRefNum = vol;
  173.                 cmpb.ioNewName = (StringPtr)0L;
  174.                 cmpb.ioNewDirID = dir;
  175.                 cmpb.ioDirID = sourcedir;
  176.                 
  177.                 PBCatMoveSync(&cmpb);
  178.             }
  179.             
  180.             // now delete the folder
  181.             HRec.ioParam.ioNamePtr = (StringPtr)name;
  182.             HRec.ioParam.ioVRefNum = vol;
  183.             HRec.fileParam.ioDirID = dir;
  184.             PBHDeleteSync(&HRec);
  185.         }
  186.     }
  187.  
  188. out:
  189.     return abort == 0 ? kWasNotAborted : kWasAborted ;
  190. }
  191.